package net.mikoo.seals.manage.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import net.mikoo.seals.biz.service.NoticeServices;
import net.mikoo.seals.biz.service.VerifyService;
import net.mikoo.seals.common.WebContext;
import net.mikoo.seals.common.enums.VerifyStatusEnum;
import net.mikoo.seals.common.model.PageModel;
import net.mikoo.seals.manage.web.common.BaseController;
import net.mikoo.seals.model.ApplyVerify;
import net.mikoo.seals.model.ApplyVerifyQuery;
import net.mikoo.seals.model.Notice;
import net.mikoo.seals.model.NoticeQuery;

@Controller
public class NoticeController extends BaseController {

	@Autowired
	private NoticeServices noticeServices;
	
	@Autowired
	private VerifyService verifyService;
	
	/**
	 * 通知列表
	 * @param query
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/notice/list")
	public String list(NoticeQuery query, HttpServletRequest request, Model model) {
		Long companyId = this.getCompanyId(request, WebContext.ADMIN_LOGIN_SESSION_KEY);
		Long partyId = getCurrentPartyId(request, WebContext.ADMIN_LOGIN_SESSION_KEY);
		query.setPartyId(partyId);
		query.setCompanyId(companyId);
		
		query.setOrderColumn("create_time");
		query.setOrderType("desc");
		
		PageModel<Notice> pm  = noticeServices.getPageByQuery(query);
		model.addAttribute("pm", pm);
		return "/notice/list";
	}
	
	/**
	 * 待办列表
	 * @param query
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/pending/list")
	public String pending(ApplyVerifyQuery query, HttpServletRequest request, Model model) {
		Long companyId = this.getCompanyId(request, WebContext.ADMIN_LOGIN_SESSION_KEY);
		Long partyId = getCurrentPartyId(request, WebContext.ADMIN_LOGIN_SESSION_KEY);
		query.setPartyId(partyId);
		query.setCompanyId(companyId);
		query.setVerifyStatus(VerifyStatusEnum.WAIT.code());
		query.setOrderColumn("create_time");
		query.setOrderType("desc");
		
		PageModel<ApplyVerify> pm  = verifyService.getPageByQuery(query);
		model.addAttribute("pm", pm);
		return "/notice/pending";
	}
	
}
